<template>
    <div class="sidebar">
        <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="sidebar.collapse"
            background-color="#324157" text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-sub-menu :index="item.index" :key="item.index">
                        <template #title>
                            <el-icon>
                                <component :is="item.icon"></component>
                            </el-icon>
                            <span>{{ item.title }}</span>
                        </template>
                        <template v-for="subItem in item.subs">
                            <el-sub-menu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
                                <template #title>{{ subItem.title }}</template>
                                <el-menu-item v-for="(threeItem, i) in subItem.subs" :key="i" :index="threeItem.index">
                                    {{ threeItem.title }}
                                </el-menu-item>
                            </el-sub-menu>
                            <el-menu-item v-else :index="subItem.index">
                                {{ subItem.title }}
                            </el-menu-item>
                        </template>
                    </el-sub-menu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <el-icon>
                            <component :is="item.icon"></component>
                        </el-icon>
                        <template #title>{{ item.title }}</template>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>


<script setup lang="ts">
import { computed } from 'vue';
import { useSidebarStore } from '../store/sidebar';
import { useRoute } from 'vue-router';

const items = [
    {
        icon: 'DocumentCopy',
        title: '风采管理',
        permiss: '3',
        index: '/tabs',
        subs: [
            {
                index: '/tabs',
                title: '风采列表',
            },
        ],
    },
    {
        icon: 'DocumentCopy',
        title: '公告管理',
        permiss: '4',
        index: '/tabs_gonggao',
        subs: [
            {
                index: '/tabs_gonggao',
                title: '公告列表',
            },
        ],
    },
    {
        icon: 'DocumentCopy',
        title: '媒体报道',
        index: '/tabs_media',
        permiss: '11',
        subs: [
            {
                index: '/tabs_media',
                title: '报道列表',
            },
        ],
    },
    {
        icon: 'User',
        title: '综合管理',
        permiss: '6',
        index: '/tabs_lunbo',
        subs: [
            {
                index: '/tabs_lunbo',
                title: '轮播图列表',
            },
            {
                title:"志愿者列表",
                index: '/voluneerManage',
            },
        ],
    },
    {
        icon: 'Notification',
        title: '数据分析',
        index: '/kmeans',
        permiss: '7',
        subs: [
            {
                index: '/startBar',
                title: '数据可视化',
            },
            // {
            // index: '/incomeHis',
            // title: '电影票房分析',
            // },
            // {
            // index: '/yearAna',
            // title: '电影年份分析',
            // },
            // {
            // index: '/regionAna',
            // title: '电影出版地区分析',
            // },
            // {
            // index: '/directorAna',
            // title: '电影导演分析',
            // },
        ]
    },
    {
        icon: 'User',
        title: '反馈管理',
        permiss: '18',
        index: '/tabs_feedBack',
    },

];

const route = useRoute();
const onRoutes = computed(() => {
    return route.path;
});

const sidebar = useSidebarStore();
</script>

<style scoped>
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow: visible;
}

.sidebar::-webkit-scrollbar {
    width: 0;
}

.sidebar-el-menu:not(.el-menu--collapse) {
    width: 250px;
}

.sidebar>ul {
    height: 100%;
}
</style>